#ifndef ALLOCATOR
#define ALLOCATOR

#include "buffer.h"

namespace sleek
{
    namespace core
    {
        namespace math
        {
            template<typename T>
            class allocator
            {
                public:
                    virtual ~allocator() {}
                    T* allocate(size_t cnt) { return (T*)internal_new(cnt* sizeof(T)); }
                    void deallocate(T* ptr) { internal_delete(ptr); }
                    void construct(T* ptr, const T&e) { new ((void*)ptr) T(e); }
                    void destruct(T* ptr) { ptr->~T(); }
                protected:
                    virtual void* internal_new(size_t cnt) { return operator new(cnt); }
                    virtual void internal_delete(void* ptr) { operator delete(ptr); }
            };
            template<typename T>
            class allocator_fast
            {
                public:
                    T* allocate(size_t cnt) { return (T*)operator new(cnt* sizeof(T)); }
                    void deallocate(T* ptr) { operator delete(ptr); }
                    void construct(T* ptr, const T&e) { new ((void*)ptr) T(e); }
                    void destruct(T* ptr) { ptr->~T(); }
            };
            enum eAllocStrategy
            {
                ALLOC_STRATEGY_SAFE    = 0,
                ALLOC_STRATEGY_DOUBLE  = 1,
                ALLOC_STRATEGY_SQRT    = 2
            };
        }
    }
}

#endif
